package web;

import entity.Teacher;
import service.TeacherService;
import service.impl.TeacherServiceImpl;


import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/*
* 将所有用户显示到控制台
* ·创建实体类 tno tname gender,birthdate;
* ·写dao，查询所有教师保存到list集合并返回
* ·写service 调用dao 获取所有的教师集合
* ·写web 调用 service 获取所用教师，并遍历输出到控制台
* */
public class TestTeacher {
    public static void main(String[] args) throws Exception{
        /*TeacherService teacherService=  new TeacherServiceImpl();
        List<Teacher> teacherList=teacherService.getTeacherList();
        //遍历输出
        for(Teacher teacher:teacherList){
            System.out.println(teacher);
        }*/
        //获取当前时间，转换为数据库可以使用的方式
       /* Date date = new Date();
        Timestamp timestamp = new Timestamp(date.getTime());
        String time="2018-05-05 11:11:45";
        Timestamp timestamp1 = Timestamp.valueOf(time);
        //将 timestamp 转换为字符串
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd HH:MM:SS");
        String format = simpleDateFormat.format(timestamp1);
        //date转字符串
        String format1 = simpleDateFormat.format(date);
        //字符串转日期
        //Date parse = simpleDateFormat.parse(time);*/

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd HH:MM:SS");

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入编号：");
        int tno = scanner.nextInt();
        System.out.print("请输入用户名：");
        String name = scanner.next();
        System.out.print("请输入性别：");
        String gender = scanner.next();
        System.out.print("请输入出生日期：");
        String birthdate = scanner.next();
        Date parse = simpleDateFormat.parse(birthdate);
        Teacher teacher = new Teacher(tno,name,gender,parse);
        TeacherService teacherService = new TeacherServiceImpl();
        teacherService.addTeacher(teacher);
    }

}
